/*****************************************************
*                                                                          
*               COPYRIGHT (c) 2015-2017 Hargic Corporation                 
*                         All Rights Reserved                              
*                                                                          
* The source code contained or described herein and all documents          
* related to the source code ("Material") are owned by Hargic            
* Corporation or its licensors.  Title to the Material remains             
* with Hargic Corporation or its suppliers and licensors.                  
*                                                                          
* The Material is protected by worldwide copyright and trade secret        
* laws and treaty provisions. No part of the Material may be used,         
* copied, reproduced, modified, published, uploaded, posted, transmitted,  
* distributed, or disclosed in any way except in accordance with the       
* applicable license agreement.                                            
*                                                                          
* No license under any patent, copyright, trade secret or other            
* intellectual property right is granted to or conferred upon you by       
* disclosure or delivery of the Materials, either expressly, by            
* implication, inducement, estoppel, except in accordance with the         
* applicable license agreement.                                            
*                                                                          
* Unless otherwise agreed by Hargic in writing, you may not remove or      
* alter this notice or any other notice embedded in Materials by Hargic    
* or Hargic's suppliers or licensors in any way.                           
*                                                                          
** Author: shengda.huang
** Date: 2018-05-18
*
*****************************************************/

#ifndef __RF433_H_
#define __RF433_H_

#ifdef __cplusplus
extern "C"{
#endif

/***** INCLUDES *************************************/

/***** DEFINES **************************************/

#define RF433_HEAD_ST			0xdead

#define RF433_VERSION			1

#define RF433_INVALID_ADDR		0xffff

enum
{
	RF433_MSG_SLAVE_REG_REQ = 1,
	RF433_MSG_SLAVE_REQ_RSP,
	RF433_MSG_SLAVE_REPORT_SWITCH_REQ,
	RF433_MSG_SLAVE_REPORT_SWITCH_RSP,
	RF433_MSG_SLAVE_REPORT_VALUE_REQ,
	RF433_MSG_SLAVE_REPORT_VALUE_RSP,
	RF433_MSG_HOST_SWITCH_REQ,
	RF433_MSG_HOST_SWITCH_RSP,
	RF433_MSG_HOST_VALUE_REQ,
	RF433_MSG_HOST_VALUE_RSP,
};

enum
{
	RF433_DEV_TYPE_SWITCH_OUTPUT = 1,
	RF433_DEV_TYPE_SWITCH_INPUT,
	RF433_DEV_TYPE_VALUE_OUTPUT,
	RF433_DEV_TYPE_VALUE_INPUT,
};

enum
{
	RF433_RST_TYPE_SUSS = 1,
	RF433_RST_TYPE_STU_ERR,
	RF433_RST_TYPE_NOT_SUPPORT,
	RF433_RST_TYPE_DEV_ERR,
	RF433_RST_TYPE_VER_NOT_SUPPORT,
};

enum
{
	RF433_ADDR_LOCK = 12301,
	RF433_ADDR_READER,
	RF433_ADDR_MAG,
	RF433_ADDR_BUTTON,
};

/***** TYPEDEFS *************************************/
	
typedef struct 
{
	unsigned short 	head;
	unsigned short  addr;
	unsigned char   hostid[3];
	unsigned char  	bodylen;
	unsigned short  seq;
	unsigned short  msgtype;
	unsigned short 	crc;
} rf433_header_t;

#pragma pack (1)

typedef struct 
{
	unsigned short	dev;
	unsigned char 	ver;
	unsigned char 	id[20];
} rf433_register_req_t ;

typedef struct 
{
	unsigned short  addr;
	int 			result;
	unsigned char   hostid[3];
} rf433_register_resp_t;

#pragma pack ()

/***** CONSTANTS ************************************/

/***** VARIABLES ************************************/

/***** EXTERNAL VARIABLES ***************************/

extern unsigned char master_hostid[3];

/***** EXTERNAL FUNCTIONS ***************************/

/***** PROTOTYPES ***********************************/
void rf433_init(void);
int rf433_create_pkg(unsigned char *buff, unsigned int maxlen, unsigned short addr, unsigned short seq, unsigned short msgtype, unsigned int bodylen);
int rf433_msg_handler(unsigned char *buff, unsigned int len);


#ifdef __cplusplus
}
#endif

#endif /* __RF433_H_ */

